home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
lisp
/
eulisp
/
mpfeel.lha
/
MPFeel
/
Modules
/
phil.em
< prev
next >
Wrap
Lisp/Scheme
|
1992-10-06
|
2KB
|
72 lines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; EuLisp Module Copyright (C) University of Bath 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmodule phil
(standard0 ellis)
;; (lists
;; list-operators
;; extras
;; streams
;; arith
;;
;; linda-base
;; linda-tabs
;; linda
;; vectors
;; threads
;; semaphores)
()
;; Our linda pool...
(deflocal phil-pool (make-local-pool))
;; and scheduler
(deflocal phil-scheduler (make-local-linda-scheduler))
;; Parameter...
(deflocal Num 6)
;; Philosopher process...
(defun phil (i)
(tilnil
(prin i) (print " is thinking")
(linda-in phil-pool (tuple 'room-ticket))
(print "GOT TICKET")
(linda-in phil-pool (tuple 'chopstick i))
(print "GOT CS 1")
(linda-in phil-pool (tuple 'chopstick (remainder (+ i 1) Num)))
(prin i) (print " is pigging out")
(linda-out phil-pool (tuple 'chopstick i))
(linda-out phil-pool (tuple 'chopstick (remainder (+ i 1) Num)))
(linda-out phil-pool (tuple 'room-ticket))
(thread-reschedule)))
(defun init () (init-aux Num))
(defun init-aux (n)
(if (= n 0)
(progn
(prin "init complete for ") (prin Num) (print " philosophers")
;; (linda-in phil-pool (tuple 'zombie))
(thread-suspend))
(progn
(linda-out phil-pool (tuple 'chopstick (- n 1)))
(prin "phil ") (prin (- n 1))
(prin " is ") (print (linda-start phil-scheduler phil (- n 1)))
(if (< (- n 1) (- Num 1))
(linda-out phil-pool (tuple 'room-ticket))
nil)
(init-aux (- n 1)))))
)